<template>
    <header class="m-header">
        <span @click="leftClick" :class="leftClass"><i></i><i></i><i></i></span>
        <span class="center">{{title}}</span>
        <span @click="rightClick" class="right">
            <slot name="right"></slot>
        </span>
    </header>
</template>
<script>
export default {

    name: 'header',

    props: {
        leftType: {
            type: String,
            default: 'back'
        },
        back: {
            type: String,
            default: ''
        },
        title: {
            type: String,
            default: '未命名'
        },
    },

    created() {
        var tthis = this;
    },

    activated() {

    },

    computed: {
        leftClass() {
            let vClass = 'left ';
            if (this.leftType == 'back') {
                vClass += 'back';
            } else if (this.leftType == 'menu') {
                vClass += 'menu';
            }
            return vClass;
        }
    },

    methods: {
        leftClick() {
            if (this.leftType == 'back') {
                let backName = this.back;
                if(backName){
                    this.$router.push({
                        name:backName
                    })
                    // console.log(backName)
                }else{
                    this.$router.goBack();
                }
            } else if (this.leftType == 'menu') {
                this.$store.commit('setMenuShow', true);
            }
        },
        rightClick() {

        }
    }
}

</script>
<style lang="less" scoped>
.m-header {
    position: relative;
    width: 100%;
    height: 44px;
    min-height: 44px;
    font-size: 16px;
    line-height: 44px;
    text-align: center;
    background-color: #fff;
    box-shadow: 0 0 5px #e2e2e2;
    border-bottom: 1px solid #e8e8e8;
    overflow: hidden;
    .left {
        position: absolute;
        left: 0;
        top: 0;
        width: 50px;
        height: 44px;
        overflow: hidden;
        &.menu {
            padding-top: 10px;
            i {
                width: 22px;
                height: 1px;
                background: #666;
                line-height: 0px;
                margin: 3px 12px;
                float: left;
            }
        }
        &.back::after,
        &.back::before {
            content: '';
            position: absolute;
            left: 16px;
            top: 12px;
            width: 0;
            height: 0;
            border-top: 10px solid transparent;
            border-bottom: 10px solid transparent;
            border-right: 10px solid #d4d4d4;
        }
        &.back::after {
            left: 18px;
            border-right-color: #fff;
        }
    }

    .center {
        width: 100%;
        display: inline-block;
    }

    .right {
        position: absolute;
        top: 0;
        right: 0;
        width: 44px;
        font-size: 18px;
        line-height: 44px;
        text-align: center;
        overflow: hidden;
    }
}

</style>
